<script setup lang="ts">
import {ElInput, ElMessage} from "element-plus";
import {getData} from "../data/KeyValueData.ts";
import {onMounted, ref} from "vue";
import {invoke} from "@tauri-apps/api/core";
import {Setting} from "../composables/AppConfig.ts";

const setList = ref<Setting[]>([]);
const downloadPath = ref('');

onMounted(() => {


  invoke('get_current_path').then((val) => {
    downloadPath.value = val as string;
    console.log(downloadPath.value);
    ElMessage.info('获取当前路径成功' + downloadPath.value);
  })

  getData('jsonData.bin').then((store) => {
    store.get('appSetting').then((val) => {
      if (val) {
        setList.value = (val as Setting[]).sort((a, b) => a.sort - b.sort);
      } else {
        setList.value = [
          {
            sort: 1,
            name: '下载地址',
            value: downloadPath?.toString() || '',
          }
        ]
      }
      store.set('appSetting', setList.value);
    })
  })
})
</script>

<template>
  <div class="setting_row" v-for="(item) in setList">
    <div clase="setting_key">{{ item.name }}</div>
    <div clase="setting_value">
      <el-input v-model="item.value" style="width: 240px" :placeholder="item.value"/>
    </div>

  </div>
</template>

<style scoped>

.setting_row {
  display: flex;
  padding: 20px;
  gap: 10px;
}
</style>